﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.SqlClient;
using System.Data;
using System.Data.Common;
using System.Collections;


/// <summary>
/// Summary description for User
/// </summary>
namespace PFSync
{
    public partial class User
    {
        public string Name { get; set; }
        public string Email { get; set; }

        public static User RestoreByPersonIdGuid(Guid guid)
        {
            Database db = DatabaseFactory.CreateDatabase("pfsync_Connection");


            string sqlCommand = "SELECT * from [user] WHERE person_id_h_v=@id_user";

            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            // Add in parameters
            db.AddInParameter(dbCommand, "@id_user", DbType.String, guid.ToString());

            IDataReader myReader = db.ExecuteReader(dbCommand);
            PFSync.User u = new PFSync.User();
            if (myReader.Read())
            {
                u = new PFSync.User(myReader);
            }
            myReader.Close();
            dbCommand.Connection.Close();

            return u;
        }

    }
}
